# U-Boot: Marvell Kirkwood platforms
# Maintainer: Kevin Mihelich <kevin@archlinuxarm.org>
# Maintainer: Oleg Rakhmanov <oleg@archlinuxarm.org>

buildarch=2

pkgbase=uboot-kirkwood
pkgname=('uboot-dockstar' 'uboot-goflexhome' 'uboot-goflexnet' 'uboot-pogo_e02' 'uboot-pogoplugv4' 'uboot-nsa310' 'uboot-nsa325' 'uboot-nsa320' 'uboot-guruplug' 'uboot-sheevaplug')
pkgver=2016.09
_commit=9c386a6152dd05691c2a972d4d898cda96563d4b
pkgrel=1
arch=('arm')
url="https://github.com/archlinuxarm/u-boot"
license=('GPL')
depends=('uboot-tools' 'mtd-utils')
source=("https://github.com/moonman/u-boot/archive/${_commit}.tar.gz"
        'uboot-dockstar.txt'
        'uboot-goflexhome.txt'
        'uboot-goflexnet.txt'
        'uboot-pogo_e02.txt'
        'uboot-pogoplugv4.txt'
        'uboot-nsa310.txt'
        'uboot-nsa325.txt'
        'uboot-nsa320.txt'
        'uboot-guruplug.txt'
        'uboot-sheevaplug.txt')
md5sums=('0eaeab86c1ff45978abe5062598c1cf2'
         '50f4cf74fc0993435f8b18d028a3c006'
         '0a92d44729e81669525b0b4393974aa1'
         '8d64678dacb49d191f5fba42045e0637'
         'c4eae149aabd571c01b4ec38a1da3da0'
         '5608f2b2b89a214fe079718de1d75df2'
         '60933ca914d393de2f5c4a2d3b21e394'
         '56a342174c72513b71f58e41182c2204'
         '88c86409d25bcac06bd7456d60258a34'
         '691953980b0a1c12d6ef768781b60f09'
         '39cfec42fc01141adb7e84dfca18bf4a')

build() {
  cd u-boot-${_commit}

  unset CFLAGS CXXFLAGS LDFLAGS
  
  mkdir bins
  for i in dockstar goflexhome goflexnet pogo_e02 pogoplugv4 nsa310 nsa325 nsa320 guruplug sheevaplug; do 
    msg2 "Building for ${i}"

    # Sort all commands in alphabetical order
    sort -bd -o uboot-${i}.txt ${srcdir}/uboot-${i}.txt

    # Make flashable env file out of a text file
    mkenvimage -s 0x20000 -o bins/uboot-${i}.env uboot-${i}.txt

    # Build U-Boot finally
    make distclean
    make ${i}_config
    make u-boot.kwb EXTRAVERSION=-${pkgrel}
    dd if=u-boot.kwb of=bins/uboot-${i}.kwb bs=512k conv=sync
  done;
}

package_uboot-dockstar() {
  pkgdesc="U-Boot for the Seagate FreeAgent DockStar"
  install="$pkgname.install"

  mkdir -p "${pkgdir}"/boot
  cp u-boot-${_commit}/bins/uboot-dockstar.{kwb,env} "${pkgdir}"/boot
}

package_uboot-goflexhome() {
  pkgdesc="U-Boot for the Seagate GoFlex Home"
  install="$pkgname.install"

  mkdir -p "${pkgdir}"/boot
  cp u-boot-${_commit}/bins/uboot-goflexhome.{kwb,env} "${pkgdir}"/boot
}

package_uboot-goflexnet() {
  pkgdesc="U-Boot for the Seagate GoFlex Net"
  install="$pkgname.install"

  mkdir -p "${pkgdir}"/boot
  cp u-boot-${_commit}/bins/uboot-goflexnet.{kwb,env} "${pkgdir}"/boot
}

package_uboot-pogo_e02() {
  pkgdesc="U-Boot for the Pogoplug V2 (E02)"
  install="$pkgname.install"

  mkdir -p "${pkgdir}"/boot
  cp u-boot-${_commit}/bins/uboot-pogo_e02.{kwb,env} "${pkgdir}"/boot
}

package_uboot-pogoplugv4() {
  pkgdesc="U-Boot for the Pogoplug V4 & Pogoplug Mobile"
  depends+=('pogoplug-blparam')
  install="$pkgname.install"

  mkdir -p "${pkgdir}"/boot
  cp u-boot-${_commit}/bins/uboot-pogoplugv4.{kwb,env} "${pkgdir}"/boot
}

package_uboot-nsa325() {
  pkgdesc="U-Boot for the Zyxel NSA325"
  install="$pkgname.install"

  mkdir -p "${pkgdir}"/boot
  cp u-boot-${_commit}/bins/uboot-nsa325.{kwb,env} "${pkgdir}"/boot
}

package_uboot-nsa320() {
  pkgdesc="U-Boot for the Zyxel NSA320"
  install="$pkgname.install"

  mkdir -p "${pkgdir}"/boot
  cp u-boot-${_commit}/bins/uboot-nsa320.{kwb,env} "${pkgdir}"/boot
}

package_uboot-nsa310() {
  pkgdesc="U-Boot for the Zyxel NSA310"
  install="$pkgname.install"

  mkdir -p "${pkgdir}"/boot
  cp u-boot-${_commit}/bins/uboot-nsa310.{kwb,env} "${pkgdir}"/boot
}

package_uboot-guruplug() {
  pkgdesc="U-Boot for the Guruplug (plus)"
  install="$pkgname.install"

  mkdir -p "${pkgdir}"/boot
  cp u-boot-${_commit}/bins/uboot-guruplug.{kwb,env} "${pkgdir}"/boot
}

package_uboot-sheevaplug() {
  pkgdesc="U-Boot for the Sheevaplug (esata)"
  install="$pkgname.install"

  mkdir -p "${pkgdir}"/boot
  cp u-boot-${_commit}/bins/uboot-sheevaplug.{kwb,env} "${pkgdir}"/boot
}
